X-Git-Url: https://git.r.bdr.sh/rbdr/super-polarity/blobdiff_plain/38c7d3f9eb7d63937c6654ff5dd6046ce02dd59c..3de51c6f55d304f038df1b77c8ab346e2a187fe1:/Super%20Polarity/Actors/Actor.cs diff --git a/Super Polarity/Actors/Actor.cs b/Super Polarity/Actors/Actor.cs index 588ff14..3bb06be 100644 --- a/Super Polarity/Actors/Actor.cs +++ b/Super Polarity/Actors/Actor.cs @@ -10,7 +10,7 @@ namespace SuperPolarity { class Actor { - protected Game game; + protected SuperPolarity game; public List Children; @@ -18,6 +18,9 @@ namespace SuperPolarity protected Texture2D Texture; protected Vector2 Origin; public bool Active; + public Rectangle Box; + public Vector4 BoxDimensions; + protected Texture2D BoxTexture; // Physical Properties public Vector2 Position; @@ -26,8 +29,15 @@ namespace SuperPolarity public float Angle; // Constraints / Behavior - protected float MaxVelocity; + public float MaxVelocity; protected float AccelerationRate; + public int HP; + protected bool Immortal; + public bool Dying; + public int Value; + protected Color Color; + + public Actor Parent; public int Width { @@ -39,9 +49,13 @@ namespace SuperPolarity get { return Texture.Height; } } - public Actor(Game newGame) + public Actor(SuperPolarity newGame) { game = newGame; + BoxDimensions.X = 20; + BoxDimensions.Y = 20; + BoxDimensions.W = 15; + BoxDimensions.Z = 15; } public virtual void Initialize(Texture2D texture, Vector2 position) @@ -58,6 +72,23 @@ namespace SuperPolarity MaxVelocity = 5; AccelerationRate = 10; + + HP = 1; + Immortal = false; + + Dying = false; + Value = 1; + + InitBox(); + BoxTexture = new Texture2D(game.GraphicsDevice, 1, 1); + BoxTexture.SetData(new Color[] { Color.White }); + + Color = Color.White; + } + + protected void InitBox() + { + Box = new Rectangle((int)(Position.X - BoxDimensions.X), (int)(Position.Y - BoxDimensions.X), (int)(BoxDimensions.X + BoxDimensions.X + BoxDimensions.W), (int)(BoxDimensions.Y + BoxDimensions.Y + BoxDimensions.Z)); } public void AutoDeccelerate(GameTime gameTime) @@ -120,6 +151,13 @@ namespace SuperPolarity Move(gameTime); ChangeAngle(); CheckOutliers(); + UpdateBox(); + } + + protected virtual void UpdateBox() + { + Box.X = (int)(Position.X - BoxDimensions.X); + Box.Y = (int)(Position.Y - BoxDimensions.Y); } public virtual void Move(GameTime gameTime) @@ -157,17 +195,30 @@ namespace SuperPolarity public void ChangeAngle() { + if (Math.Abs(Velocity.Y) <= 0.1 && Math.Abs(Velocity.X) <= 0.1) + { + return; + } Angle = (float)Math.Atan2(Velocity.Y, Velocity.X); } public virtual void Draw(SpriteBatch spriteBatch) { - foreach (Actor child in Children) + Actor child = null; + + // TODO: Check what's up with the null children. + if (Children == null) + { + return; + } + for (var i = Children.Count - 1; i >= 0; i--) { + child = Children[i]; child.Draw(spriteBatch); } - spriteBatch.Draw(Texture, Position, null, Color.White, Angle, Origin, 1f, SpriteEffects.None, 0f); + spriteBatch.Draw(Texture, Position, null, Color, Angle, Origin, 1f, SpriteEffects.None, 0f); + //spriteBatch.Draw(BoxTexture, Box, new Color(255, 0, 255, 25)); } void CheckOutliers() @@ -183,5 +234,34 @@ namespace SuperPolarity } } } + + public virtual void Collide(Actor other, Rectangle collision) + { + } + + public void TakeDamage(int amount) + { + if (!Immortal) + { + HP = HP - amount; + if (HP < 0) + { + Die(); + } + } + } + + protected virtual void Die() + { + Dying = true; + } + + public virtual void CleanUp() + { + Texture = null; + BoxTexture = null; + Children = null; + Texture = null; + } } }